from threading import Thread,Lock
import time

# 写一个程序模拟简单的银行存钱系统

BankAccount = {
    'jxc':0
}

BankAccount_lock = Lock()


def Addmoney(thredidx,money):

    BankAccount_lock.acquire()  # 启动锁
    BaseMoney = BankAccount['jxc']
    time.sleep(0.2)
    BankAccount['jxc'] = BaseMoney + money
    print(f'子线程{thredidx}结束')

    BankAccount_lock.release()  # 关闭锁


Thread_list = []

for idx in range(1,11):
    thread = Thread(target=Addmoney,
                    args=(idx,1)
                    )

    Thread_list.append(idx)

    thread.start()


for idx in Thread_list:

    thread.join()

print('主线程结束')
print('现在银行账户里的存款有：',BankAccount['jxc'])
